package cn.lanqiao.bigDate.web.controller;

import cn.lanqiao.bigDate.entity.data.DataPbhouse;
import cn.lanqiao.bigDate.reslut.Result;
import cn.lanqiao.bigDate.web.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(DataPbhouseController.BASE_URL)
public class DataPbhouseController extends BaseController {
    public static final String BASE_URL = "dataPbhouse";
    /**
     * 页面跳转
     * @return
     */
    @RequestMapping(value = "toIndex")
    public ModelAndView toIndex() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName(BASE_URL + "/index"); //指定路径
        return mav;
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping(value = "findByPage")
    public IPage<DataPbhouse> findByPage(Page<DataPbhouse> page, String searchDeptName) {
            return dataPbhouseService.findByPage(page,searchDeptName);
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping(value = "findDataPbhouseOne")
    public DataPbhouse findDataPbhouseOne(Long id) {
        return dataPbhouseService.findDataPbhouseOne(id);
    }

    /**
     * 修改
     * @param dataPbhouse
     * @return
     */
    @PostMapping(value = "updateDataPbhouse")
    public Result<String> findDataPbhouseOne(DataPbhouse dataPbhouse) {
        System.out.println(dataPbhouse);
        Result<String> reslut = new Result();
        Boolean isSuccess = dataPbhouseService.updateDataPbhouse(dataPbhouse);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("修改成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("修改失败");
        }
        return reslut;
    }
    /**
     * 添加
     * @param dataPbhouse
     * @return
     */
    @PostMapping(value = "saveDataPbhouse")
    public Result<String> saveDataPbhouse(DataPbhouse dataPbhouse) {
        Result<String> reslut = new Result();
        Boolean isSuccess = dataPbhouseService.saveDataPbhouse(dataPbhouse);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("添加成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("添加失败");
        }
        return reslut;
    }

    /**
     * 按id删除
     * @param ids
     * @return
     */
    @RequestMapping(value = "deleteDataPbhouse")
    public Result<String> deleteDataPbhouse(String ids) {
        String s = String.valueOf(ids);
        Result<String> reslut = new Result();
        Boolean isSuccess = dataPbhouseService.deleteDataPbhouse(s);
        if(isSuccess){
            reslut.setCode(200);
            reslut.setMsg("删除成功");
        }else{
            reslut.setCode(500);
            reslut.setMsg("删除失败");
        }
        return reslut;
    }

}
